-
Notifications
You must be signed in to change notification settings - Fork 51
Add new generic add method #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add new generic add method #530
Conversation
…he data serialization
self.assertEqual(root.FirstNode.objects()[0].type.value, "RequiredPlugin") | ||
self.assertEqual(root.FirstNode.objects()[0].name.value, "FirstNode") | ||
|
||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass |
self.assertEqual(root.objects()[0].type.value, "RequiredPlugin") | ||
self.assertEqual(root.objects()[0].name.value, "FirstNode") | ||
|
||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass |
root.add(MyNode) | ||
self.assertEqual(root.children()[0].name.value, "MyNode") | ||
|
||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass |
} | ||
} | ||
|
||
py::object add( Node* self, const std::string& type, const py::kwargs& kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to add a second signature so we can pass real type instead of string.
py::object add( Node* self, py::type type, const py::kwargs& kwargs)
{
if(issubchild(type, BaseObject)){
...
}else if(issubchild(type, Node)){
....
}
}
But this could be in a second PR.
name = py::str(kwargs["name"]); | ||
if (sofapython3::isProtectedKeyword(name)) | ||
throw py::value_error("Cannot call addObject with name " + name + ": Protected keyword"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we consider to add a name generation mechanism (with +1) to avoid having name duplicated.
Of course this have a non linear performance hit in case of gigantic scene... but I would be in favor of having a robust normal add() and a second one considered "fast mode" for expert users.
This method's goal is to reduce as much as possible thee data serialization